package com.zhongjinkang.rhythm.viewModel

import android.util.Log
import androidx.lifecycle.MutableLiveData
import com.zhongjinkang.rhythm.Model.LoginModel
import com.zhongjinkang.rhythm.network.api.HttpCallBack
import com.zhongjinkang.rhythm.network.res.UserRes

class LoginViewModel : BaseViewModel<LoginModel>(LoginModel()) {

    var loginState = MutableLiveData<LoginState>(LoginState.Fail)
    var message: String = ""

    init {

    }

    fun goToLogin() {

        model?.let {
            it.requestLogin(
                object : HttpCallBack<UserRes> {
                    override fun onSuccess(data: UserRes) {
                        loginState.value = LoginState.SUCCESS
                        it.saveUserInfoList()

                    }
                    override fun onFail(code: Int, message: String) {
                        loginState.value = LoginState.Fail
                        this@LoginViewModel.message = message

                    }

                }

            )
        }
    }

    enum class LoginState {
        SUCCESS, Fail

    }

}